﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using BLToolkit.DataAccess;
using BLToolkit.Common;
using BLToolkit.Data.Linq;
using BLToolkit.Mapping;

namespace Core
{
    [TableName("tblKhenThuong")]
    public class KhenThuong
    {
        [PrimaryKey, Identity]
        [MapField("MaKhenThuong")]
        public int ID { get; set; }

        public string MucKhenThuong { get; set; }
        public string MoTa { get; set; }

        // FK_tblCB_KT_tblKhenThuong1
        [Association(ThisKey = "MaKT", OtherKey = "MaKhenThuong", CanBeNull = true)]
        public List<CanBoKhenThuong> CanBo_KhenThuongs { get; set; }

        public static IQueryable<KhenThuong> KhenThuongs
        {
            get
            {
                using (var db = new DataContext())
                {
                    return db.GetTable<KhenThuong>();
                }
            }
        }
        public static List<KhenThuong> All()
        {
            return KhenThuongs.ToList();
        }
        public static KhenThuong Single(int id)
        {
            return KhenThuongs.SingleOrDefault(x => x.ID == id);
        }
        public static int Add(KhenThuong entity)
        {
            using (var db = new DataContext())
            {
                object rs = db.InsertWithIdentity(entity);
                return int.Parse(rs.ToString());
            }
        }
        public static int Update(KhenThuong entity)
        {
            using (var db = new DataContext())
            {
                return db.Update(entity);
            }
        }
        public static int Delete(int id)
        {
            return KhenThuongs.Delete(x => x.ID == id);
        }
    }
}
